$NG.AllReady(
    function (editPage, { useAction, useValuesChange, useClick, useBeforeClick }) {
        var table_d = $NG.getCmpApi('p_form_jhcf_d');
        var table1 = $NG.getCmpApi('p_form_jhcf_d1');
        console.log('初始化!!!');

        table_d.subscribe(function () {
            // 获取当前选中的行索引
            var checkedIndexes = table_d.getCheckedIndexes();
            console.log(table_d.getSelectedRow().u_sj_code);

            $NG.updateUI((updater) => {
                updater.editGrid.p_form_jhcf_d1.u_sj_code.setProps(prev => ({
                    ...prev, editor: {
                        ...prev.editor, clientSqlFilter({ row }) {
                            return ("u_sj_code ='" + table_d.getSelectedRow().u_sj_code + "'")
                        }
                    }
                }));
            });
        }, 'onCheckedChange')

        /**增加拆分 add by pxc 20231224 **/
        const toolbar_d = $NG.getCmpApi('toolbar_p_form_jhcf_d');
        const toolbar_d2 = $NG.getCmpApi('toolbar_p_form_jhcf_d1');
        const dg1 = $NG.getCmpApi('p_form_jhcf_d');
        const dg2 = $NG.getCmpApi('p_form_jhcf_d1');
        //增行
        useBeforeClick(function ({ args }) {
            console.log('useBeforeClick')
            $NG.updateState((updater) => {
                updater.data.p_form_jhcf_d.setProps((ds) => {
                    return [...ds, { rel_key1: $NG.uniqueId() }];
                });
            });
            return false;
        }, 'p_form_jhcf_d.addrow');

        //添加拆分一级按钮
        toolbar_d.insert({
            id: "split_row",
            name: "split_row",
            text: "拆分一级",
            langKey: "split_row",
            iconCls: "icon-DeleteRow",
            onClick: () => {
                splitRow(dg1, dg2, 1);
            },
        });
        //添加拆分二级按钮
        toolbar_d2.insert({
            id: "split_row2",
            name: "split_row2",
            text: "拆分二级",
            langKey: "split_row2",
            iconCls: "icon-DeleteRow",
            onClick: () => {
                splitRow(dg1, dg2, 2);
            },
        });
        //拆行函数
        function splitRow(dg1, dg2, level) {
            if (level == 1) {
                const selData1 = dg1.getSelectedRow();
                let node_type1 = '';
                switch (selData1.u_type) {
                    case '一级节点':
                        node_type1 = '二级节点';
                        break;
                    case '二级节点':
                        node_type1 = '三级节点';
                        break;
                    case '三级节点':
                        node_type1 = '四级节点';
                        break;
                }
                dg2.addRows({
                    rel_key1: selData1.rel_key1,
                    u_source_plan_m_id: selData1.u_source_m_phid,
                    u_sj_code: selData1.u_sj_code,
                    u_sj_name: selData1.u_sj_name,
                    u_type: node_type1,
                    u_type_name: node_type1,
                    u_sdt: selData1.u_sdt_c,
                    u_edt: selData1.u_edt_c,
                    u_jhgq: selData1.u_jhgq_c,
                    u_zrr: selData1.u_zrr,
                    u_zrr_name: selData1.u_zrr_name,
                    u_xzr: selData1.u_xzr,
                    u_xzr_name: selData1.u_xzr_name
                });
            }
            if (level == 2) {
                const selData2 = dg2.getSelectedRow();
                let node_type2 = '';
                switch (selData2.u_type) {
                    case '二级节点':
                        node_type2 = '三级节点';
                        break;
                    case '三级节点':
                        node_type2 = '四级节点';
                        break;
                    case '四级节点':
                        node_type2 = '';
                        break;
                }
                dg2.addRows({
                    rel_key1: selData2.rel_key1,
                    u_source_plan_m_id: selData2.u_source_plan_m_id,
                    u_sj_code: selData2.u_code,
                    u_sj_name: selData2.u_name,
                    u_type: node_type2,
                    u_type_name: node_type2,
                    u_sdt: selData2.u_sdt,
                    u_edt: selData2.u_edt,
                    u_jhgq: selData2.u_jhgq,
                    u_zrr: selData2.u_zrr,
                    u_zrr_name: selData2.u_zrr_name,
                    u_xzr: selData2.u_xzr,
                    u_xzr_name: selData2.u_xzr_name
                });
            }
        }
        //点击主明细过滤子明细
        dg1.subscribe(function ({ rowIndex, table }) {
            console.log(rowIndex);
            const store = table.store;
            const rel_key1 = table.getRow(rowIndex).rel_key1;
            // const rel_key1 = store.data[rowIndex].rel_key1;
            //更新子明细
            $NG.updateState((updater) => {
                return updater.data.p_form_jhcf_d1.setProps((ds) => {
                    console.log('ds', ds)
                    //if(ds.length>0){
                    return ds.filter(item => item.rel_key1 === rel_key1
                    )
                    //}
                });
            });
        }, 'clickHighlight');

    });